Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

LDAP Connection script on Script Runner Resources

Dino Carreon February 29, 2020

I was able to successfully setup the ldap connection but when I tried to run the sample script:

import com.onresolve.scriptrunner.ldap.LdapUtil

def cnList = LdapUtil.withTemplate('corporate') {

template -> template.search("", "(sn=Smi*)", SearchControls.SUBTREE_SCOPE, { attributes ->

          attributes.get('cn').get() } as AttributesMapper<String>)

}

I'm getting the error: Unable to resolve class AttributesMapper

 

Jira version 8.5.1

Script Runner version: 5.7.0.1-p5

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Joanna Choules
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2020

Hi,

It appears that the example code is missing some imports. In full, I believe it should be:

import com.onresolve.scriptrunner.ldap.LdapUtil
import org.springframework.ldap.core.AttributesMapper
import javax.naming.directory.SearchControls
import javax.naming.directory.Attributes

def cnList = LdapUtil.withTemplate('corporate') { template ->
template.search("", "(sn=Smi*)", SearchControls.SUBTREE_SCOPE, { Attributes attributes ->
attributes.get('cn').get()
} as AttributesMapper<String>)
}

NB. Annotating the attributes parameter as being of type Attributes is only done to satisfy the static type checker: it can safely be left out without changing the way the code behaves at run time.

Kind regards,

Joanna Choules, Adaptavist Product Support

Dino Carreon March 4, 2020

Thank you! works now.

aas December 2, 2020

Hello

But where can I download com.onresolve.scriptrunner.ldap.LdapUtil ? There no any jars on https://mvnrepository.com/maven

Joanna Choules
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 6, 2021

Hi,

There is no need to download and import `LdapUtil` separately: it is part of the regular ScriptRunner installation.

Ravi Gunaratne June 25, 2021

HI @Joanna Choules ,

 

I used the same code any Idea why am I getting

org.springframework.ldap.PartialResultException: Unprocessed Continuation Reference(s); nested exception is javax.naming.PartialResultException: Unprocessed Continuation Reference(s); remaining name ''

 

 

Error.

 

Thanks

Ravi

0 votes
Jorge December 20, 2022

Hi @Joanna Choules 

How would I modify the script if I want to get the "company" attribute from a user?

Jorge January 13, 2023

Hello! @Joanna Choules 

I was actually able to do this and the script returns a list of users that belong to the company I need.

However, there seem to be inactive and invalid users on the returned list. 

Any idea how to get rid of them?

 

Thanks!

Stefan Salzl
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 13, 2023

@Jorge 

would you be so kind to share your code? I do have a very similar requirement: I need to filter for the ‚department‘ attribute.

Could your problem be resolved meanwhile?

Best
Stefan

Jorge July 31, 2023
Hi Stefan,
I would change to (department= your department name)
Let me know if you have any questions.

import com.onresolve.scriptrunner.ldap.LdapUtil

import org.springframework.ldap.core.AttributesMapper

import javax.naming.directory.SearchControls

import javax.naming.directory.Attributes

def cnList = LdapUtil.withTemplate('YourResource') { template ->

    template.search("", "(company=YourCompany)", SearchControls.SUBTREE_SCOPE, { Attributes attributes ->

        attributes.get('sAMAccountName').get()

    } as AttributesMapper<String>)

}

// cnList now contains the list of users where company = Your company name
Like Stefan Salzl likes this
TAGS
AUG Leaders

Atlassian Community Events